<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>管理站点 | 欢迎学习django课程</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../part1/5.html" />
    
    
    <link rel="prev" href="../part1/3.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="1.3"
        data-chapter-title="管理站点"
        data-filepath="part1/4.md"
        data-basepath=".."
        data-revision="Tue Jan 03 2017 08:43:08 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        课程介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="part1/1.html">
            
                
                    <a href="../part1/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        入门
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="part1/2.html">
            
                
                    <a href="../part1/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        搭建开发环境
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="part1/3.html">
            
                
                    <a href="../part1/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        设计模型
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="1.3" data-path="part1/4.html">
            
                
                    <a href="../part1/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        管理站点
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="part1/5.html">
            
                
                    <a href="../part1/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        视图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="part1/6.html">
            
                
                    <a href="../part1/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        模板
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="part1/7.html">
            
                
                    <a href="../part1/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="part2/1.html">
            
                
                    <a href="../part2/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        模型
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="part2/2.html">
            
                
                    <a href="../part2/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        定义模型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="part2/3.html">
            
                
                    <a href="../part2/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        模型成员
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="part2/4.html">
            
                
                    <a href="../part2/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        模型查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="part2/5.html">
            
                
                    <a href="../part2/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        自连接
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="part2/6.html">
            
                
                    <a href="../part2/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="part3/1.html">
            
                
                    <a href="../part3/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        视图
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="part3/2.html">
            
                
                    <a href="../part3/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        URLconf
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="part3/3.html">
            
                
                    <a href="../part3/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        视图函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="part3/4.html">
            
                
                    <a href="../part3/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        Request对象
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="part3/4_1.html">
            
                
                    <a href="../part3/4_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.1.</b>
                        
                        QueryDict对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="part3/4_2.html">
            
                
                    <a href="../part3/4_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.2.</b>
                        
                        GET属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.3" data-path="part3/4_3.html">
            
                
                    <a href="../part3/4_3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.3.</b>
                        
                        POST属性
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="part3/5.html">
            
                
                    <a href="../part3/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        Response对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="part3/6.html">
            
                
                    <a href="../part3/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        状态保持
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="part3/7.html">
            
                
                    <a href="../part3/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="part4/1.html">
            
                
                    <a href="../part4/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        模板
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="part4/2.html">
            
                
                    <a href="../part4/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        定义模板
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="part4/3.html">
            
                
                    <a href="../part4/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        模板继承
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="part4/4.html">
            
                
                    <a href="../part4/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        HTML转义
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="part4/5.html">
            
                
                    <a href="../part4/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        CSRF
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="part4/6.html">
            
                
                    <a href="../part4/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        验证码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="part4/7.html">
            
                
                    <a href="../part4/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="part5/1.html">
            
                
                    <a href="../part5/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        高级
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="part5/2.html">
            
                
                    <a href="../part5/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        静态文件处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="part5/3.html">
            
                
                    <a href="../part5/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        中间件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="part5/4.html">
            
                
                    <a href="../part5/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        上传图片
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="part5/5.html">
            
                
                    <a href="../part5/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        Admin站点
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="part5/6.html">
            
                
                    <a href="../part5/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        分页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="part5/7.html">
            
                
                    <a href="../part5/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        ajax
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="part5/8.html">
            
                
                    <a href="../part5/8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="part6/1.html">
            
                
                    <a href="../part6/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        第三方
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="part6/2.html">
            
                
                    <a href="../part6/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        富文本编辑器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="part6/3.html">
            
                
                    <a href="../part6/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        缓存
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="part6/4.html">
            
                
                    <a href="../part6/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        全文检索
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="part6/5.html">
            
                
                    <a href="../part6/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        celery
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="part6/6.html">
            
                
                    <a href="../part6/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        布署
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="part6/7.html">
            
                
                    <a href="../part6/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="part7/1.html">
            
                
                    <a href="../part7/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        Git与项目
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="part7/2.html">
            
                
                    <a href="../part7/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        Git简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.1" data-path="part7/2_2.html">
            
                
                    <a href="../part7/2_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.1.</b>
                        
                        远程仓库
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.1.2" data-path="part7/2_1.html">
            
                
                    <a href="../part7/2_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.2.</b>
                        
                        本地仓库
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="part7/3.html">
            
                
                    <a href="../part7/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        项目设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="part7/4.html">
            
                
                    <a href="../part7/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        模型类设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="part7/5.html">
            
                
                    <a href="../part7/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        使用页面
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="part7/6.html">
            
                
                    <a href="../part7/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >欢迎学习django课程</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x670D;&#x52A1;&#x5668;">&#x670D;&#x52A1;&#x5668;</h1>
<ul>
<li>&#x8FD0;&#x884C;&#x5982;&#x4E0B;&#x547D;&#x4EE4;&#x53EF;&#x4EE5;&#x5F00;&#x542F;&#x670D;&#x52A1;&#x5668;</li>
</ul>
<pre><code>python manage.py runserver ip:port
</code></pre><ul>
<li>&#x53EF;&#x4EE5;&#x4E0D;&#x5199;ip&#xFF0C;&#x9ED8;&#x8BA4;&#x7AEF;&#x53E3;&#x4E3A;8000</li>
<li>&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x7EAF;python&#x7F16;&#x5199;&#x7684;&#x8F7B;&#x91CF;&#x7EA7;web&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x4EC5;&#x5728;&#x5F00;&#x53D1;&#x9636;&#x6BB5;&#x4F7F;&#x7528;</li>
<li>&#x670D;&#x52A1;&#x5668;&#x6210;&#x529F;&#x542F;&#x52A8;&#x540E;&#xFF0C;&#x63D0;&#x793A;&#x5982;&#x4E0B;&#x4FE1;&#x606F;</li>
</ul>
<p><img src="images/server.png" alt="&#x670D;&#x52A1;&#x5668;"></p>
<ul>
<li>&#x9ED8;&#x8BA4;&#x7AEF;&#x53E3;&#x662F;8000&#xFF0C;&#x53EF;&#x4EE5;&#x4FEE;&#x6539;&#x7AEF;&#x53E3;</li>
</ul>
<pre><code>python manage.py runserver 8080
</code></pre><ul>
<li>&#x6253;&#x5F00;&#x6D4F;&#x89C8;&#x5668;&#xFF0C;&#x8F93;&#x5165;&#x7F51;&#x5740;&#x201C;127.0.0.1:8000&#x201D;&#x53EF;&#x4EE5;&#x6253;&#x5F00;&#x9ED8;&#x8BA4;&#x9875;&#x9762;</li>
<li>&#x5982;&#x679C;&#x4FEE;&#x6539;&#x6587;&#x4EF6;&#x4E0D;&#x9700;&#x8981;&#x91CD;&#x542F;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x5982;&#x679C;&#x589E;&#x5220;&#x6587;&#x4EF6;&#x9700;&#x8981;&#x91CD;&#x542F;&#x670D;&#x52A1;&#x5668;</li>
<li>&#x901A;&#x8FC7;ctrl+c&#x505C;&#x6B62;&#x670D;&#x52A1;&#x5668;</li>
</ul>
<h1 id="&#x7BA1;&#x7406;&#x64CD;&#x4F5C;">&#x7BA1;&#x7406;&#x64CD;&#x4F5C;</h1>
<ul>
<li>&#x7AD9;&#x70B9;&#x5206;&#x4E3A;&#x201C;&#x5185;&#x5BB9;&#x53D1;&#x5E03;&#x201D;&#x548C;&#x201C;&#x516C;&#x5171;&#x8BBF;&#x95EE;&#x201D;&#x4E24;&#x90E8;&#x5206;</li>
<li>&#x201C;&#x5185;&#x5BB9;&#x53D1;&#x5E03;&#x201D;&#x7684;&#x90E8;&#x5206;&#x8D1F;&#x8D23;&#x6DFB;&#x52A0;&#x3001;&#x4FEE;&#x6539;&#x3001;&#x5220;&#x9664;&#x5185;&#x5BB9;&#xFF0C;&#x5F00;&#x53D1;&#x8FD9;&#x4E9B;&#x91CD;&#x590D;&#x7684;&#x529F;&#x80FD;&#x662F;&#x4E00;&#x4EF6;&#x5355;&#x8C03;&#x4E4F;&#x5473;&#x3001;&#x7F3A;&#x4E4F;&#x521B;&#x9020;&#x529B;&#x7684;&#x5DE5;&#x4F5C;&#x3002;&#x4E3A;&#x6B64;&#xFF0C;Django&#x4F1A;&#x6839;&#x636E;&#x5B9A;&#x4E49;&#x7684;&#x6A21;&#x578B;&#x7C7B;&#x5B8C;&#x5168;&#x81EA;&#x52A8;&#x5730;&#x751F;&#x6210;&#x7BA1;&#x7406;&#x6A21;&#x5757;</li>
</ul>
<h4 id="&#x4F7F;&#x7528;django&#x7684;&#x7BA1;&#x7406;">&#x4F7F;&#x7528;django&#x7684;&#x7BA1;&#x7406;</h4>
<ul>
<li>&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7BA1;&#x7406;&#x5458;&#x7528;&#x6237;</li>
</ul>
<pre><code>python manage.py createsuperuser&#xFF0C;&#x6309;&#x63D0;&#x793A;&#x8F93;&#x5165;&#x7528;&#x6237;&#x540D;&#x3001;&#x90AE;&#x7BB1;&#x3001;&#x5BC6;&#x7801;
</code></pre><ul>
<li>&#x542F;&#x52A8;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x901A;&#x8FC7;&#x201C;127.0.0.1:8000/admin&#x201D;&#x8BBF;&#x95EE;&#xFF0C;&#x8F93;&#x5165;&#x4E0A;&#x9762;&#x521B;&#x5EFA;&#x7684;&#x7528;&#x6237;&#x540D;&#x3001;&#x5BC6;&#x7801;&#x5B8C;&#x6210;&#x767B;&#x5F55;</li>
<li>&#x8FDB;&#x5165;&#x7BA1;&#x7406;&#x7AD9;&#x70B9;&#xFF0C;&#x9ED8;&#x8BA4;&#x53EF;&#x4EE5;&#x5BF9;groups&#x3001;users&#x8FDB;&#x884C;&#x7BA1;&#x7406;</li>
</ul>
<h4 id="&#x7BA1;&#x7406;&#x754C;&#x9762;&#x672C;&#x5730;&#x5316;">&#x7BA1;&#x7406;&#x754C;&#x9762;&#x672C;&#x5730;&#x5316;</h4>
<ul>
<li>&#x7F16;&#x8F91;settings.py&#x6587;&#x4EF6;&#xFF0C;&#x8BBE;&#x7F6E;&#x7F16;&#x7801;&#x3001;&#x65F6;&#x533A;</li>
</ul>
<pre><code>LANGUAGE_CODE = &apos;zh-Hans&apos;
TIME_ZONE = &apos;Asia/Shanghai&apos;
</code></pre><h4 id="&#x5411;admin&#x6CE8;&#x518C;booktest&#x7684;&#x6A21;&#x578B;">&#x5411;admin&#x6CE8;&#x518C;booktest&#x7684;&#x6A21;&#x578B;</h4>
<ul>
<li>&#x6253;&#x5F00;booktest/admin.py&#x6587;&#x4EF6;&#xFF0C;&#x6CE8;&#x518C;&#x6A21;&#x578B;</li>
</ul>
<pre><code>from django.contrib import admin
from models import BookInfo
admin.site.register(BookInfo)
</code></pre><ul>
<li>&#x5237;&#x65B0;&#x7BA1;&#x7406;&#x9875;&#x9762;&#xFF0C;&#x53EF;&#x4EE5;&#x5BF9;BookInfo&#x7684;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x589E;&#x5220;&#x6539;&#x67E5;&#x64CD;&#x4F5C;</li>
<li>&#x95EE;&#x9898;&#xFF1A;&#x5982;&#x679C;&#x5728;str&#x65B9;&#x6CD5;&#x4E2D;&#x8FD4;&#x56DE;&#x4E2D;&#x6587;&#xFF0C;&#x5728;&#x4FEE;&#x6539;&#x548C;&#x6DFB;&#x52A0;&#x65F6;&#x4F1A;&#x62A5;ascii&#x7684;&#x9519;&#x8BEF;</li>
<li>&#x89E3;&#x51B3;&#xFF1A;&#x5728;str()&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x5C06;&#x5B57;&#x7B26;&#x4E32;&#x672B;&#x5C3E;&#x6DFB;&#x52A0;&#x201C;.encode(&apos;utf-8&apos;)&#x201D;</li>
</ul>
<h4 id="&#x81EA;&#x5B9A;&#x4E49;&#x7BA1;&#x7406;&#x9875;&#x9762;">&#x81EA;&#x5B9A;&#x4E49;&#x7BA1;&#x7406;&#x9875;&#x9762;</h4>
<ul>
<li>Django&#x63D0;&#x4F9B;&#x4E86;admin.ModelAdmin&#x7C7B;</li>
<li>&#x901A;&#x8FC7;&#x5B9A;&#x4E49;ModelAdmin&#x7684;&#x5B50;&#x7C7B;&#xFF0C;&#x6765;&#x5B9A;&#x4E49;&#x6A21;&#x578B;&#x5728;Admin&#x754C;&#x9762;&#x7684;&#x663E;&#x793A;&#x65B9;&#x5F0F;</li>
</ul>
<pre><code>class QuestionAdmin(admin.ModelAdmin):
    ...
admin.site.register(Question, QuestionAdmin)
</code></pre><h6 id="&#x5217;&#x8868;&#x9875;&#x5C5E;&#x6027;">&#x5217;&#x8868;&#x9875;&#x5C5E;&#x6027;</h6>
<ul>
<li>list_display&#xFF1A;&#x663E;&#x793A;&#x5B57;&#x6BB5;&#xFF0C;&#x53EF;&#x4EE5;&#x70B9;&#x51FB;&#x5217;&#x5934;&#x8FDB;&#x884C;&#x6392;&#x5E8F;</li>
</ul>
<pre><code>list_display = [&apos;pk&apos;, &apos;btitle&apos;, &apos;bpub_date&apos;]
</code></pre><ul>
<li>list_filter&#xFF1A;&#x8FC7;&#x6EE4;&#x5B57;&#x6BB5;&#xFF0C;&#x8FC7;&#x6EE4;&#x6846;&#x4F1A;&#x51FA;&#x73B0;&#x5728;&#x53F3;&#x4FA7;</li>
</ul>
<pre><code>list_filter = [&apos;btitle&apos;]
</code></pre><ul>
<li>search_fields&#xFF1A;&#x641C;&#x7D22;&#x5B57;&#x6BB5;&#xFF0C;&#x641C;&#x7D22;&#x6846;&#x4F1A;&#x51FA;&#x73B0;&#x5728;&#x4E0A;&#x4FA7;</li>
</ul>
<pre><code>search_fields = [&apos;btitle&apos;]
</code></pre><ul>
<li>list_per_page&#xFF1A;&#x5206;&#x9875;&#xFF0C;&#x5206;&#x9875;&#x6846;&#x4F1A;&#x51FA;&#x73B0;&#x5728;&#x4E0B;&#x4FA7;</li>
</ul>
<pre><code>list_per_page = 10
</code></pre><h6 id="&#x6DFB;&#x52A0;&#x3001;&#x4FEE;&#x6539;&#x9875;&#x5C5E;&#x6027;">&#x6DFB;&#x52A0;&#x3001;&#x4FEE;&#x6539;&#x9875;&#x5C5E;&#x6027;</h6>
<ul>
<li>fields&#xFF1A;&#x5C5E;&#x6027;&#x7684;&#x5148;&#x540E;&#x987A;&#x5E8F;</li>
</ul>
<pre><code>fields = [&apos;bpub_date&apos;, &apos;btitle&apos;]
</code></pre><ul>
<li>fieldsets&#xFF1A;&#x5C5E;&#x6027;&#x5206;&#x7EC4;</li>
</ul>
<pre><code>fieldsets = [
    (&apos;basic&apos;,{&apos;fields&apos;: [&apos;btitle&apos;]}),
    (&apos;more&apos;, {&apos;fields&apos;: [&apos;bpub_date&apos;]}),
]
</code></pre><h4 id="&#x5173;&#x8054;&#x5BF9;&#x8C61;">&#x5173;&#x8054;&#x5BF9;&#x8C61;</h4>
<ul>
<li><p>&#x5BF9;&#x4E8E;HeroInfo&#x6A21;&#x578B;&#x7C7B;&#xFF0C;&#x6709;&#x4E24;&#x79CD;&#x6CE8;&#x518C;&#x65B9;&#x5F0F;</p>
<ul>
<li>&#x65B9;&#x5F0F;&#x4E00;&#xFF1A;&#x4E0E;BookInfo&#x6A21;&#x578B;&#x7C7B;&#x76F8;&#x540C;</li>
<li>&#x65B9;&#x5F0F;&#x4E8C;&#xFF1A;&#x5173;&#x8054;&#x6CE8;&#x518C;</li>
</ul>
</li>
<li><p>&#x6309;&#x7167;BookInfor&#x7684;&#x6CE8;&#x518C;&#x65B9;&#x5F0F;&#x5B8C;&#x6210;HeroInfo&#x7684;&#x6CE8;&#x518C;</p>
</li>
<li>&#x63A5;&#x4E0B;&#x6765;&#x5B9E;&#x73B0;&#x5173;&#x8054;&#x6CE8;&#x518C;</li>
</ul>
<pre><code>from django.contrib import admin
from models import BookInfo,HeroInfo

class HeroInfoInline(admin.StackedInline):
    model = HeroInfo
    extra = 2

class BookInfoAdmin(admin.ModelAdmin):
    inlines = [HeroInfoInline]

admin.site.register(BookInfo, BookInfoAdmin)
</code></pre><ul>
<li>&#x53EF;&#x4EE5;&#x5C06;&#x5185;&#x5D4C;&#x7684;&#x65B9;&#x5F0F;&#x6539;&#x4E3A;&#x8868;&#x683C;</li>
</ul>
<pre><code>class HeroInfoInline(admin.TabularInline)
</code></pre><h4 id="&#x5E03;&#x5C14;&#x503C;&#x7684;&#x663E;&#x793A;">&#x5E03;&#x5C14;&#x503C;&#x7684;&#x663E;&#x793A;</h4>
<ul>
<li>&#x53D1;&#x5E03;&#x6027;&#x522B;&#x7684;&#x663E;&#x793A;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;&#x76F4;&#x89C2;&#x7684;&#x7ED3;&#x679C;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x5C01;&#x88C5;</li>
</ul>
<pre><code>def gender(self):
    if self.hgender:
        return &apos;&#x7537;&apos;
    else:
        return &apos;&#x5973;&apos;
gender.short_description = &apos;&#x6027;&#x522B;&apos;
</code></pre><ul>
<li>&#x5728;admin&#x6CE8;&#x518C;&#x4E2D;&#x4F7F;&#x7528;gender&#x4EE3;&#x66FF;hgender</li>
</ul>
<pre><code>class HeroInfoAdmin(admin.ModelAdmin):
    list_display = [&apos;id&apos;, &apos;hname&apos;, &apos;gender&apos;, &apos;hcontent&apos;]
</code></pre>
                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../part1/3.html" class="navigation navigation-prev " aria-label="Previous page: 设计模型"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../part1/5.html" class="navigation navigation-next " aria-label="Next page: 视图"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
